package br.com.viamais.business.bean;

import java.util.List;

import br.com.viamais.business.IProfileBO;
import br.com.viamais.dao.ProfileDAO;
import br.com.viamais.model.Profile;

/**
 * <B>Project: viamais-web</B><BR>
 * 
 * BusinessObject to treat the Profile's Business rules.
 * 
 * <DL>
 * <DT><B>Created:</B>
 * <DD>Oct 3, 2011</DD></DT>
 * </DL>
 * <DL>
 * <DT><B>Last Modification:</B>
 * <DD>Oct 3, 2011</DD></DT>
 * </DL>
 * 
 * @author Caio Carleto - CarSer - Oct 3, 2011
 * @version 1.0
 */
// TODO implement log.
public class ProfileBO implements IProfileBO {
	/**
	 * Serial Version ID
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * Profile DAO instance.
	 */
	private ProfileDAO profileDAO;

	/**
	 * Constructor.
	 */
	public ProfileBO() {
		profileDAO = new ProfileDAO();
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void saveOrUpdate(Profile entity) throws Throwable {
		profileDAO.saveOrUpdate(entity);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public List<Profile> getAll() throws Throwable {
		return profileDAO.getAll();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void delete(Profile profile) throws Throwable {
		profile.deleteRoles();
		profileDAO.delete(profile);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Profile getById(Integer id) throws Throwable {
		return profileDAO.getById(id);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public List<Profile> getByName(String name) throws Throwable {
		if (name == null || name.isEmpty()) {
			name = null;
		}
		return profileDAO.getByName(name);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Profile getUniqueByName(String name) throws Throwable {
		return profileDAO.getUniqueByName(name);
	}
}
